Page({
  data: {
    expressList: []
  },

  onShow() {
    // 页面显示时刷新列表
    if (this.data.expressList.length === 0) {
      this.setData({
        expressList: []  // 设置为空数组
      })
    }
  },

  addNewExpress() {
    wx.navigateTo({
      url: '/pages/express/add/add'
    })
  },

  editExpress(e) {
    const id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/pages/express/edit/edit?id=${id}`
    })
  },

  deleteExpress(e) {
    const id = e.currentTarget.dataset.id
    wx.showModal({
      title: '提示',
      content: '确定要删除该快递单号吗？',
      success: (res) => {
        if (res.confirm) {
          const newExpressList = this.data.expressList.filter(item => item.orderNumber !== id)
          this.setData({
            expressList: newExpressList
          })
        }
      }
    })
  }
})